package ws.very.util.aws.cloudsearch

import scala.reflect.ClassTag

trait TableMapping {
  trait Fields extends Enumeration {
    abstract class Field[F: ClassTag, T: ClassTag](key: S) {
      val v = Value(key)
      def from2To(f: F): T
      def apply(s: F) = v.toString -> from2To(s)
      def renew(t: T): F
      def name = v.toString()
      override def toString = name
    }
    def Str2StrField(key: S) = new Field[S, S](key) {
      def from2To(f: S) = f.getOrElse("")
      def renew(t: S) = if (t) t else null
    }
    def rawField[T: ClassTag](k: S) = new Field[T, T](k) {
      def from2To(f: T) = f
      def renew(t: T) = t
    }
    def fieldNames = values.map { _.toString }
  }

}